﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Application.AppConfigureManage;
using Zocono.WCS.Application.AppEquipmentLayoutManage;
using Zocono.WCS.Application.AppEquipmentManage;
using Zocono.WCS.Application.AppTelegramRecordManage;
using Zocono.WCS.Application.AppUserManage;
using Zocono.WCS.Domain.BytesMapObjectDomain;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EquipmentLayoutManageDomain;
using Zocono.WCS.Domain.EquipmentManageDomain;
using Zocono.WCS.Domain.EquipmentProcessDomain.PlanarGeneralMessage;
using Zocono.WCS.Domain.JobDomain;
using Zocono.WCS.Domain.PlanarProcessServiceMapDomain;
using Zocono.WCS.Domain.PlcConnectionDomain;
using Zocono.WCS.Domain.PlcReadDbDomain;
using Zocono.WCS.Domain.PlcWriteDbDomain;
using Zocono.WCS.Domain.ProgrameDomain;
using Zocono.WCS.Domain.RouteDomain;
using Zocono.WCS.Domain.ScRowDomain;
using Zocono.WCS.Domain.StationDomain;
using Zocono.WCS.Domain.TelegramRecordInfoDomain;
using Zocono.WCS.Domain.UserManageDomain;
using Zocono.WCS.Domain.WorkTaskDomain;
using Zocono.WCS.Infrastructure.Repository;

namespace Zocono.WCS.WebApi
{
    public static class ServiceIOC
    {
        public static void AddService(IServiceCollection services)
        {

            services.AddSingleton<ISnowflake, Snowflake>();
            //用户
            services.AddScoped<IUserInfoRepository, UserInfoRepository>();
            services.AddScoped<IUserInfoService, UserInfoService>();
            services.AddScoped<UserInfoApp>();

            #region 设备管理
            //设备&类型
            services.AddScoped<EquipmentApp>();
            services.AddScoped<IEquipmentTypeRepository, EquipmentTypeRepository>();
            services.AddScoped<IEquipmentTypeService, EquipmentTypeService>();
            services.AddScoped<IDispatchEquipmentRepository, DispatchEquipmentRepository>();
            services.AddScoped<IDispatchEquipmentService, DispatchEquipmentService>();
            //设备布局&类型
            services.AddScoped<EquipmentLayoutApp>();
            services.AddScoped<IEquipmentLayoutTypeRepository, EquipmentLayoutTypeRepository>();
            services.AddScoped<IEquipmentLayoutTypeService, EquipmentLayoutTypeService>();
            services.AddScoped<IEquipmentLayoutRepository, EquipmentLayoutRepository>();
            services.AddScoped<IEquipmentLayoutService, EquipmentLayoutService>();
            #endregion

            #region 配置管理

            //程序配置
            services.AddScoped<ProgrameInfoApp>();
            services.AddScoped<IProgrameInfoRepository, ProgrameInfoRepository>();
            services.AddScoped<IProgrameService, ProgrameService>();

            //作业配置
            services.AddScoped<JobInfoApp>();
            services.AddScoped<IJobInfoRepository, JobInfoRepository>();
            services.AddScoped<IJobInfoService, JobInfoService>();

            //PLC连接配置
            services.AddScoped<PlcConnectionInfoApp>();
            services.AddScoped<IPlcConnectionInfoRepository, PlcConnectionInfoRepository>();
            services.AddScoped<IPlcConnectionInfoService, PlcConnectionInfoService>();

            //平面设备报文业务处理配置
            services.AddScoped<IPlanarProcessServiceMapInfoRepository, PlanarProcessServiceMapInfoRepository>();
            services.AddScoped<IPlanarProcessServiceMapService, PlanarProcessServiceMapService>();
            services.AddScoped<PlanarProcessServiceMapApp>();

            //plc 读db 配置
            services.AddScoped<IPlcReadDbInfoRepository, PlcReadDbInfoRepository>();
            services.AddScoped<IPlcReadDbInfoService, PlcReadDbInfoService>();
            services.AddScoped<PlcReadDbInfoApp>();

            //plc 读db 配置
            services.AddScoped<IPlcWriteDbInfoRepository, PlcWriteDbInfoRepository>();
            services.AddScoped<IPlcWriteDbInfoService, PlcWriteDbInfoService>();
            services.AddScoped<PlcWriteDbInfoApp>();

            //报文解析配置
            services.AddScoped<IBytesMapObjectInfoRepository, BytesMapObjectInfoRepository>();
            services.AddScoped<IBytesMapObjectInfoService, BytesMapObjectInfoService>();
            services.AddScoped<BytesMapObjectInfoApp>();

            //工位信息配置
            services.AddScoped<StationInfoApp>();
            services.AddScoped<IStationInfoRepository, StationInfoRepository>();
            services.AddScoped<IStationInfoService, StationInfoService>();

            //路径配置
            services.AddScoped<RouteInfoApp>();
            services.AddScoped<IRouteInfoRepository, RouteInfoRepository>();
            services.AddScoped<IRouteInfoService, RouteInfoService>();

            //路径明细配置
            services.AddScoped<RouteDetailInfoApp>();
            services.AddScoped<IRouteDetailInfoRepository, RouteDetailInfoRepository>();
            services.AddScoped<IRouteDetailInfoService, RouteDetailInfoService>();

            //堆垛机-货架排号配置
            services.AddScoped<ScRowInfoApp>();
            services.AddScoped<IScRowInfoRepository, ScRowInfoRepository>();
            services.AddScoped<IScRowInfoService, ScRowInfoService>();
            #endregion

            #region plc连接信息查询
            services.AddScoped<IPlcConnectionLockInfoRepository, PlcConnectionLockInfoRepository>();
            services.AddScoped<IPlcConnectionStateInfoRepository, PlcConnectionStateInfoRepository>();
            #endregion

            #region 任务管理

            //任务管理
            services.AddScoped<WorkTaskInfoApp>();
            services.AddScoped<IWorkTaskInfoRepository, WorkTaskInfoRepository>();
            services.AddScoped<IWorkTaskInfoServeice, WorkTaskInfoServeice>();

            services.AddScoped<TaskRouteDetailRecordInfoApp>();
            services.AddScoped<ITaskRouteDetailRecordInfoRepository, TaskRouteDetailRecordInfoRepository>();
            services.AddScoped<ITaskRouteDetailRecordInfoService, TaskRouteDetailRecordInfoService>();
            #endregion

            //报文存储
            services.AddScoped<TelegramRecordApp>();
            services.AddScoped<ITelegramRecordInfoService, TelegramRecordInfoService>();
            services.AddScoped<ITelegramRecordInfoRepository, TelegramRecordInfoRepository>();

            //服务，平面正常动作报文业务处理服务工厂
            services.AddScoped<IPlanarGeneralPlcActionProcessServiceFactory, PlanarGeneralPlcActionProcessServiceFactory>();//工厂
            services.AddScoped<IDispatchEquipmentPlanarStateRepository, DispatchEquipmentPlanarStateRepository>();
            services.AddScoped<IDispatchEquipmentRepository, DispatchEquipmentRepository>();
        }
    }
}
